package com.xiaoyu.merchant.ui.activity.wallet;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.google.gson.Gson;
import com.xiaoyu.commonlib.network.CommonHttpResponser;
import com.xiaoyu.commonlib.ui.base.BaseActivityWithTitle;
import com.xiaoyu.commonlib.utils.PreferencesUtil;
import com.xiaoyu.merchant.R;
import com.xiaoyu.merchant.model.WalletDetalsListBean;
import com.xiaoyu.merchant.network.NetworkManager;

import butterknife.BindView;
import butterknife.ButterKnife;

public class OrderDetailsActivity extends BaseActivityWithTitle {

    @BindView(R.id.activity_order_details_type)
    TextView mType;//类型
    @BindView(R.id.activity_order_details_time)
    TextView mTime;//时间
    @BindView(R.id.activity_order_details_trasaction_id)
    TextView mTrasactionId;//交易单号
    @BindView(R.id.activity_order_details_residue_money)
    TextView mResidueMoney;//剩余零钱


    @Override
    protected void loadContentView(ViewGroup parent) {
        View mView = LayoutInflater.from(this).inflate(R.layout.activity_order_details, parent, true);
        setTitleText("订单详情");
        ButterKnife.bind(this);
        getOrderDetails();
    }

    private void getOrderDetails() {
        String walletId = getIntent().getStringExtra(ParticularsActivity.BILL_WALLET_ID);
        Log.i("jx", "getOrderDetails:------ " + walletId);
        NetworkManager.walletDetails(PreferencesUtil.getString(PreferencesUtil.TOKEN,""),walletId, new CommonHttpResponser() {
            @Override
            public void onSuccess(String result) {
                succeedResult(result);
            }

            @Override
            public void onFailed(String errorCode, String errorDiscription) {
            }
        });
    }

    //解析数据
    private void succeedResult(String result) {
        WalletDetalsListBean walletParticularsBean = new Gson().fromJson(result, WalletDetalsListBean.class);
        mType.setText(walletParticularsBean.getData().getTransaction_type());//类型
        mTime.setText(walletParticularsBean.getData().getTrade_time());//时间
        mTrasactionId.setText(walletParticularsBean.getData().getTrading_number());//交易单号
        mResidueMoney.setText(walletParticularsBean.getData().getBalance());//剩余零钱
    }
}
